package com.bhs.sansong.view;

import android.content.Context;
import android.widget.TextView;

import com.bhs.sansong.R;
import com.bhs.sansong.utils.DateUtils;
import com.github.mikephil.charting.components.MarkerView;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.utils.MPPointF;

import java.util.List;

/**
 * 自定义MyMarkerView
 */
public class MyMarkerView extends MarkerView {

    private TextView tvContent;
    private TextView tvTime;
    private List<Integer> times;

    public MyMarkerView(Context context, int layoutResource, List<Integer> times) {
        super(context, layoutResource);
        tvTime = findViewById(R.id.tv_time);
        tvContent = (TextView) findViewById(R.id.tv_number);
        this.times = times;
    }

    @Override
    public void refreshContent(Entry e, Highlight highlight) {

        tvTime.setText(DateUtils.getMonthDay(times.get((int) e.getX())*1000L));
        tvContent.setText(String.format("%s单", (int)e.getY()));


        super.refreshContent(e, highlight);
    }

    @Override
    public MPPointF getOffset() {
        return new MPPointF(-(getWidth() / 2), -getHeight());
    }
}
